<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="手机号">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="日期">
      </el-table-column>
    </el-table>
    <el-pagination
      align="right"
      background
      layout="prev, pager, next"
      :total="total"
      :page-size="pageSize"
      :page-count="pageCount"
      :current-page="currentPage"
      @current-change="toPage">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      tableData: [],
      currentPage:1,
      pageCount: 1,
      total: 0,
      pageSize: 5
    }
  },
  methods: {
    getTableData() {
      let params = {"currentPage":this.currentPage, "pageSize":this.pageSize}
      this.$http.post("/user/list",params).then(res=>{
        this.tableData = res.data.data
        this.total = res.data.totals
      })
    },
    toPage(curr) {
      this.currentPage = curr
      this.getTableData();
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    }
  },
  mounted() {
    this.getTableData();
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
